version 16
set more off
set matsize 11000
 
***************************************************************************************************
*THIS FILE PRODUCES TABLE A.XIV OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************
 
/* PRELIMINARIES */
 
use						"$project_data\ITRM_Dislo_Unique_IncMPs_Light.dta", clear
drop					if treat==1
drop					treat
keep                    regno year TaxPaid we namefreq logtaxpaid
duplicates 				drop regno year, force
bys						regno:g nreturns=_N
g						bp=nreturns==10
g						treat=we==0
g						after=year>=2012
g						treat_after=treat*after
g						trend=year-2005
g						trend_treat=trend*treat
#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* COLUMN 1 */

local				i=1
local				j=1
quietly				areg logtaxpaid trend trend_treat treat after treat_after, absorb(regno) cluster(regno)
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
matrix				table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 2 */

local				i=1
quietly				areg logtaxpaid trend trend_treat treat after treat_after if bp==1, absorb(regno) cluster(regno)
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
matrix				table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 3-10 */

forvalues			n=10(10)40 {
preserve
drop				if namefreq>`n' & namefreq<=40
g					unique=(namefreq<=`n')
g					treat_after_unique=treat*after*unique
qui					areg logtaxpaid trend trend_treat treat after treat_after treat_after_unique, absorb(regno)
local				i=1
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
local				i=`i'+2
matrix				table[`i',`j']=_b[treat_after_unique]
matrix 				table[`i'+1,`j']=_se[treat_after_unique]
matrix				table[`i'+2,`j']=e(N)
local				j=`j'+1
qui					areg logtaxpaid trend trend_treat treat after treat_after treat_after_unique if bp==1, absorb(regno)
local				i=1
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
local				i=`i'+2
matrix				table[`i',`j']=_b[treat_after_unique]
matrix 				table[`i'+1,`j']=_se[treat_after_unique]
matrix				table[`i'+2,`j']=e(N)
local				j=`j'+1
restore
}


/* PLACEBO */
 
use						"$project_data\ITRM_Dislo_Unique_IncMPs_Light.dta", clear
drop					if treat==1
drop					treat
keep                    regno year TaxPaid we namefreq logtaxpaid
duplicates 				drop regno year, force
keep					if year<=2011
bys						regno:g nreturns=_N
g						bp=nreturns==6
g						treat=we==0
g						after=year>=2010
g						treat_after=treat*after
g						trend=year-2005
g						trend_treat=trend*treat

/* COLUMN 1 */

local				i=6
local				j=1
quietly				areg logtaxpaid trend trend_treat treat after treat_after, absorb(regno) cluster(regno)
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
matrix				table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 2 */

local				i=6
quietly				areg logtaxpaid trend trend_treat treat after treat_after if bp==1, absorb(regno) cluster(regno)
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
matrix				table[`i'+4,`j']=e(N)
local				j=`j'+1

/* COLUMN 3-10 */

forvalues			n=10(10)40 {
preserve
drop				if namefreq>`n' & namefreq<=40
cap					drop unique treat_after_unique
g					unique=(namefreq<=`n')
g					treat_after_unique=treat*after*unique
qui					areg logtaxpaid trend trend_treat treat after treat_after treat_after_unique, absorb(regno)
local				i=6
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
local				i=`i'+2
matrix				table[`i',`j']=_b[treat_after_unique]
matrix 				table[`i'+1,`j']=_se[treat_after_unique]
matrix				table[`i'+2,`j']=e(N)
local				j=`j'+1
qui					areg logtaxpaid trend trend_treat treat after treat_after treat_after_unique if bp==1, absorb(regno)
local				i=6
matrix				table[`i',`j']=_b[treat_after]
matrix 				table[`i'+1,`j']=_se[treat_after]
local				i=`i'+2
matrix				table[`i',`j']=_b[treat_after_unique]
matrix 				table[`i'+1,`j']=_se[treat_after_unique]
matrix				table[`i'+2,`j']=e(N)
local				j=`j'+1
restore
}

/* FORMATTING THE TABLE */ 

svmat 			table
keep			tab*
drop			table9-table12
keep			if _n<=10
g				c11=""
replace			c11="SE $\times$ after" in 1
replace			c11="SE $\times$ after $\times$ unique" in 3
replace			c11="Observations" in 5
replace			c11="SE $\times$ after" in 6
replace			c11="SE $\times$ after $\times$ unique" in 8
replace			c11="Observations" in 10

forvalues 		c=1/8 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 4 7 9 {
forvalues		c=1/8 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/8 {
replace			c`c'=string(table`c',"%15.0fc") in 5
replace			c`c'=string(table`c',"%15.0fc") in 10
}
forvalues		c=1/2 {
foreach			r in 3 4 8 9 {
replace			c`c'="" in `r'
}
}
forvalues		s=1/15 {
g				s`s'="&"
}
g				l="\\"
order			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 l
browse			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 l
